package com.zmzncs.lmtc.module.shop.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zmzncs.lmtc.common.pojo.PageInfo;
import com.zmzncs.lmtc.common.pojo.Rest;
import com.zmzncs.lmtc.common.util.JsonUtil;
import com.zmzncs.lmtc.common.util.RestUtil;
import com.zmzncs.lmtc.module.shop.pojo.shop_slide_show.*;
import com.zmzncs.lmtc.module.shop.service.ShopSlideShowService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotNull;

/**
 * <p>
 * 商户-轮播图 前端控制器
 * </p>
 *
 * @author 高博文
 * @since 2021-05-28
 */
@RestController
@RequestMapping("/shop/shop-slide-show")
public class ShopSlideShowController {

    @Autowired
    ShopSlideShowService shopSlideShowService;

    @ApiOperation(value = "轮播图-添加商品")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "token", value = "请求头token", required = true),
            @ApiImplicitParam(paramType="query", name = "itemId", value = "商品Id", required = true),
            @ApiImplicitParam(paramType="query", name = "itemType", value = "商品类型（1：商品，2：优惠券", required = true),
            @ApiImplicitParam(paramType="query", name = "fileUrl", value = "轮播图地址", required = true),
    })
    @PostMapping("add")
    public Rest add(@NotNull Long itemId,@NotNull Integer itemType, @NotNull String fileUrl){
        shopSlideShowService.add(itemId,itemType,fileUrl);
        return RestUtil.success();
    }

    @ApiOperation(value = "分页查询轮播图")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "token", value = "请求头token", required = true),
            @ApiImplicitParam(paramType="query", name = "currentPage", value = "页码", required = true),
            @ApiImplicitParam(paramType="query", name = "pageSize", value = "每页记录数", required = true),
    })
    @GetMapping("getShopSlideShowPage")
    public Rest<PageInfo<ShopSlideShowTableVO>> getGoodsSlideShowPage(@NotNull Integer currentPage, @NotNull Integer pageSize){
        IPage<ShopSlideShowDTO> shopInfoPage = shopSlideShowService.getShopSlideShowPage(currentPage,pageSize);
        PageInfo<ShopSlideShowTableVO> pageInfo = JsonUtil.pageTransform(shopInfoPage, ShopSlideShowTableVO.class);
        return RestUtil.success(pageInfo);
    }

    @ApiOperation(value = "根据ID查询轮播图")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "token", value = "请求头token", required = true),
            @ApiImplicitParam(paramType="query", name = "showId", value = "商品轮播图id", required = true),
    })
    @GetMapping("getShopSlideShowInfo")
    public Rest<ShopSlideShowInfoVO> getGoodsSlideShowInfo(@NotNull Long showId){
        ShopSlideShowDTO showDTO = shopSlideShowService.getShopSlideShowInfo(showId);
        ShopSlideShowInfoVO showInfoVO = new ShopSlideShowInfoVO();
        BeanUtils.copyProperties(showDTO,showInfoVO);

        return RestUtil.success(showInfoVO);
    }

    @ApiOperation(value = "根据ID更新轮播图")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "token", value = "请求头token", required = true),
    })
    @PostMapping("update")
    public Rest update(@NotNull ShopSlideShowUpdateForm form){
        ShopSlideShow show = new ShopSlideShow();
        BeanUtils.copyProperties(form,show);
        shopSlideShowService.updateById(show);

        return RestUtil.success();
    }

    @ApiOperation(value = "删除轮播图")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "token", value = "请求头token", required = true),
            @ApiImplicitParam(paramType="query", name = "showId", value = "商品轮播图id", required = true),
    })
    @PostMapping("delete")
    public Rest delete(@NotNull Long showId){
        ShopSlideShow show = new ShopSlideShow();
        show.setId(showId);
        show.setIsDeleted(1);
        shopSlideShowService.updateById(show);

        return RestUtil.success();
    }

    @ApiOperation(value = "轮播图是否展示")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "token", value = "请求头token", required = true),
            @ApiImplicitParam(paramType="query", name = "showId", value = "商品轮播图id", required = true),
            @ApiImplicitParam(paramType="query", name = "isShow", value = "是否展示（1：展示，2：不展示）", required = true),
    })
    @PostMapping("isShow")
    public Rest isShow(@NotNull Long showId,@NotNull Integer isShow){
        ShopSlideShow show = new ShopSlideShow();
        show.setId(showId);
        show.setIsShow(isShow);
        shopSlideShowService.updateById(show);


        return RestUtil.success();
    }



}

